<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>icf</title>

  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/public/layui/admin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/public/layui/admin/style/admin.css" media="all">
</head>

<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header">Product</div>
      <div class="layui-card-body" style="padding: 15px;">
        <form class="layui-form" action="" lay-filter="component-form-group">
          {% if data.detail.Id %}
          <input name="id" type="hidden" value="{{ data.detail.Id }}" />
          {% endif %}

          <!-- todo #FormFieldsHtml# -->

          <!--
<div class="layui-form-item">
	<label class="layui-form-label">id</label>
	<div class="layui-input-block">
		<input type="text"
			   id="id"
			   name="id"
			   value="{{ data.detail.Id }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->
          <!--
<div class="layui-form-item">
	<label class="layui-form-label">deleted</label>
	<div class="layui-input-block">
		<input type="text"
			   id="if_del"
			   name="if_del"
			   value="{{ data.detail.IfDel }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->

          <div class="layui-tab layui-tab-card">

            <ul class="layui-tab-title">
              <li class="layui-this">基础信息</li>
              <li>规格信息</li>
              <li>商品详情</li>
            </ul>

          </div>
          <div class="layui-tab-content" style="height: 100px;">
            <div class="layui-tab-item layui-show">
              <!-- <div class="layui-form-item">
                <label class="layui-form-label">create</label>
                <div class="layui-input-block">
                  <input type="text" id="cdate" name="cdate" value="{{ data.detail.Cdate }}" lay-verify="title"
                    autocomplete="off" placeholder="" class="layui-input">
                </div>
              </div>


              <div class="layui-form-item">
                <label class="layui-form-label">update</label>
                <div class="layui-input-block">
                  <input type="text" id="udate" name="udate" value="{{ data.detail.Udate }}" lay-verify="title"
                    autocomplete="off" placeholder="" class="layui-input">
                </div>
              </div> -->


              <div class="layui-form-item">
                <label class="layui-form-label">商品名称</label>
                <div class="layui-input-block">
                  <input type="text" id="product_name" name="product_name" value="{{ data.detail.ProductName }}"
                    lay-verify="title" autocomplete="off" placeholder="" class="layui-input" readonly>
                </div>
              </div>



              <div class="layui-form-item">
                <label class="layui-form-label">商品图片</label>
                <div class="layui-input-block">

                  <img src="{{ data.detail.DefaultImage }}" height="100px">
                  <!-- <input type="text" id="default_image" name="default_image" value="{{ data.detail.DefaultImage }}"
                    lay-verify="title" autocomplete="off" placeholder="" class="layui-input"> -->
                </div>
              </div>



              <div class="layui-form-item">
                <label class="layui-form-label">视频</label>
                <div class="layui-input-block">

                  <video width="320" height="240" controls="controls">'
                    <source src="{{ data.detail.Video }}" type="video/mp4" />
                    <object data="{{ data.detail.Video }}" width="320" height="240">
                      <embed width="320" height="240" src="{{ data.detail.Video }}" />
                    </object>
                  </video>

                  <!-- <input type="hidden" id="video" name="video" value="{{ data.detail.Video }}" />
                  <div class="layui-upload-drag" id="upload-drag">
                    <i class="layui-icon"></i>
                    <p>点击上传图片</p>
                    <img id="img-upload" src="{{ data.detail.Video }}" style="width: 100%">
                  </div> -->
                </div>
              </div>



              <div class="layui-form-item">
                <label class="layui-form-label">运费</label>
                <div class="layui-input-block">
                  <input type="text" id="postage" name="postage" value="{{ data.detail.Postage }}" lay-verify="title"
                    autocomplete="off" placeholder="" class="layui-input" readonly>
                </div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label">销售状态</label>
                <div class="layui-input-block">

                  {% if data.detail.IfSale %}
                  <input type="text" id="if_sale" name="if_sale" value="销售中" lay-verify="title" autocomplete="off"
                    placeholder="" class="layui-input">
                  {% else %}
                  <input type="text" id="if_sale" name="if_sale" value="下架" lay-verify="title" autocomplete="off"
                    placeholder="" class="layui-input">
                  {% endif %}
                </div>
              </div>



              <div class="layui-form-item">
                <label class="layui-form-label">所属店铺</label>
                <div class="layui-input-block">
                  <input type="text" id="e_shop_id" name="e_shop_id" value="{{ data.detail.EShopId }}"
                    lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
                </div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label">关联租户</label>
                <div class="layui-input-block">
                  <input type="text" id="tenant_id" name="tenant_id" value="{{ data.detail.TenantId }}"
                    lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
                </div>
              </div>

            </div>

            <div class="layui-tab-item">规格信息</div>
            <!-- 表格 -->

            <table class="layui-hide" id="data-table" lay-filter="data-table"></table>

            <div class="layui-tab-item">

              <div class="layui-form-item">
                <label class="layui-form-label">商品详情</label>
                <div class="layui-input-block">

                  <input type="hidden" id="field_desc" name="field_desc" value="{{ data.detail.Description }}"
                    lay-verify="title" autocomplete="off" placeholder="" class="layui-input">

                  <script id="editorDesc" type="text/plain" style="height:250px; z-index:-10000;"></script>

                  <!-- <input type="text" id="description" name="description" value="{{ data.detail.Description }}"
                    lay-verify="title" autocomplete="off" placeholder="" class="layui-input"> -->
                </div>
              </div>

            </div>

          </div>







          <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
              <div class="layui-footer" style="left: 0;">
                <!-- <button class="layui-btn" lay-submit="" lay-filter="edit-submit">提交</button> -->
                <a href="javascript:goBack()" class="layui-btn layui-btn-primary">返回</a>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>


  <script src="/public/layui/admin/layui/layui.js"></script>
  <script>
    layui.config({
      base: '/public/layui/admin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'jquery', 'upload'], function () {
      var $ = layui.$,
        admin = layui.admin,
        element = layui.element,
        layer = layui.layer,
        laydate = layui.laydate,
        form = layui.form;

      var table = layui.table;
      table.render({
        elem: '#data-table',
        url: '/admin/ProductSpec/listjson?product_id={{data.detail.id}}',
        where: {
          "keyword": ""
        },
        cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
          ,
        cols: [
          [
            //#TableJsonFields#
            {
              field: 'spec_name',
              title: 'spec_name',
              hide: false
            },
            {
              field: 'sell_price',
              title: 'sell_price',
              hide: false
            },
            {
              field: 'stock',
              title: 'stock',
              hide: false
            }
          ]
        ],
        page: true
      });


      form.render(null, 'component-form-group');
      laydate.render({
        elem: '#LAY-component-form-group-date'
      });

      /* 自定义验证规则 */
      form.verify({
        title: function (value) {
          if (value.length < 0) {
            return '请输入';
          }
        },
        pass: [/(.+){6,12}$/, '密码必须6到12位'],
        content: function (value) {
          layedit.sync(editIndex);
        }
      });

      // 文件上传
      var upload = layui.upload;
      upload.render({
        elem: '#upload-drag',
        url: '/admin/upload',
        done: function (res) {
          console.log(res)
          $("#img-upload").attr("src", res.data.imgurl);
          // TODO: $("#prdminipic").val(res.data.imgurl);
        }
      });

      // /* 监听提交 */
      // form.on('submit(edit-submit)', function (data) {
      //   // parent.layer.alert(JSON.stringify(data.field), {
      //   //   title: '最终的提交信息'
      //   // })
      //   $.ajax({
      //     type: "POST",
      //     url: "/admin/Product/editpage",
      //     data: data.field,
      //     async: true,
      //     error: function (request) {
      //       parent.layer.alert(JSON.stringify(request), {
      //         title: '操作失败'
      //       });
      //     },
      //     success: function (response) {
      //       console.log(response);
      //       //var rt = JSON.parse(response);
      //       var rt = response
      //       if (rt.code == 0) {
      //         var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
      //         parent.layer.close(index);
      //       } else {
      //         parent.layer.alert(rt.msg, {
      //           title: '操作失败'
      //         });
      //       }
      //     }
      //   });
      //   return false;
      // });


      init();

      function init() {
        // 图文内容
        let description = '{{data.detail.Description}}';
        console.log("================2", description);
        let base = new Base64();
        let content2 = base.decode(description);

        let ue2 = UE.getEditor('editorDesc');
        //对编辑器的操作最好在编辑器ready之后再做
        ue2.addListener("ready", function () {
          console.log("content2:", content2);
          ue2.setContent(content2);
        });
      }

      /* 监听指定开关
      form.on('switch(component-form-switchTest)', function(data){
        layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
          offset: '6px'
        });
        layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
      });*/
    });

    // 页面返回上一页面
    function goBack() {
      var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
      parent.layer.close(index);
    };
  </script>
</body>

</html>